//
//  PersonalDetailsVC.m
//  SelfDriving
//
//  Created by apple on 16/4/11.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "PersonalDetailsVC.h"
#import "ValidateHelper.h"
#import "ImageService.h"
#import "RegisterSViewController.h"
@interface PersonalDetailsVC ()
@property (weak, nonatomic) IBOutlet UIImageView *head_img_bg;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *btn_n;
@property (weak, nonatomic) IBOutlet UIButton *btn_v;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIView *view_bg;
@property (weak, nonatomic) IBOutlet UIView *head_view;
@property (weak, nonatomic) IBOutlet UILabel *ageLabel;


@property (weak, nonatomic) IBOutlet UIView *nameView;
@property (weak, nonatomic) IBOutlet UIImageView *jdimg;

@property (weak, nonatomic) IBOutlet UIView *ageView;
@property (weak, nonatomic) IBOutlet UIView *timeView;
@property (weak, nonatomic) IBOutlet UIView *headView;


@end

@implementation PersonalDetailsVC
{
    UIButton *jdbtn;
}
-(void)viewWillAppear:(BOOL)animated{
    [[AppDelegate shareDelegate]refuser:_model.uid success:^(id as) {
        _model = as;
        [self initView];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //xhw2018-1-18改bug15235查看他人资料时不显示完善进度
    if (_model.uid == [AppDelegate shareDelegate].user.uid) {
        
    }
    else {
        _jdimg.hidden = YES;
    }
    
    
}
#pragma mark 设置阴影
-(void)setyy:(UIView *)view{
    view.layer.shadowColor = [UIColor grayColor].CGColor;
    view.layer.shadowOffset = CGSizeMake(0,0);
    view.layer.shadowOpacity = 0.8f;
    view.layer.shadowRadius = 4.f;
 }
-(void)viewWillDisappear:(BOOL)animated{
    [jdbtn removeFromSuperview];
}
-(void)initView{
    for(UIView *view in [_view_bg subviews]){
        [view removeFromSuperview];
    }
    self.view.backgroundColor = UIColorFromRGB(0xEDEEEF);
    _nameLabel.text = _model.nickname;
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(_head_img_bg.frame.origin.x+3, _head_img_bg.frame.origin.y+3, _head_img_bg.frame.size.width-6, _head_img_bg.frame.size.height-6)];
    img.layer.cornerRadius = (_head_img_bg.frame.size.height-3)/2;
    img.clipsToBounds = YES;
    [ValidateHelper setImage:_model.headsmall img:img istoux:YES];
    [_head_view addSubview:img];
    _ageLabel.text = [NSString stringWithFormat:@"%@岁",[ValidateHelper timeToAge:_model.age]];
    _timeLabel.text =[ValidateHelper doubleConvertDate:[_model.age doubleValue] FormatterStr:@"yyyy-MM-dd"];
    int  w  = [_model.completion intValue];
    
    
    //进度完成条
    UILabel *jd = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, (SCRE_WIDTH*w)/100, 6)];
    jd.backgroundColor = UIColorFromRGB(0xC1F2BB);
    [_jdimg addSubview:jd];
    
    jdbtn = [[UIButton alloc]initWithFrame:CGRectMake(jd.frame.size.width-10, 50, 22, 17)];
    [jdbtn setBackgroundImage:[UIImage imageNamed:@"进度条---冒泡框"] forState:UIControlStateNormal];
    [jdbtn setTitle:[NSString stringWithFormat:@"%d％",w] forState:UIControlStateNormal];
    [jdbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    jdbtn.titleLabel.font = [UIFont systemFontOfSize:8];
    jdbtn.titleEdgeInsets = UIEdgeInsetsMake(-2, 0, 0, 0);
    [[UIApplication sharedApplication].keyWindow addSubview:jdbtn];
    
    if (w == 100) {
        jdbtn.hidden = YES;  //xhw2018-3-9加
    }
    
    _nameView.layer.cornerRadius = 3;
    
    [self setyy:_nameView];
    [self setyy:_head_view];
    [self setyy:_timeView];
    [self setyy:_ageView];
    [self setyy:_view_bg];

    _head_view.layer.cornerRadius = 3;
    
    _timeView.layer.cornerRadius = 3;
    
    _ageView.layer.cornerRadius = 3;
    
    _view_bg.layer.cornerRadius = 3;
    
    [_btn_n setImage:[ImageService imageWithColor:UIColorFromRGB(0x83D06C) img:_btn_n.imageView.image] forState:UIControlStateSelected];
    [_btn_v setImage:[ImageService imageWithColor:UIColorFromRGB(0xfaa5a8) img:_btn_v.imageView.image] forState:UIControlStateSelected];
    
    if ([_model.gender integerValue]== 0 ) {
        _btn_n.selected = YES;
        _btn_v.selected = NO;
    }else{
        _btn_v.selected = YES;
        _btn_n.selected = NO;
    }
    if ([[AppDelegate shareDelegate].user.uid intValue] == [_model.uid intValue]) {
        UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"xqbj"] style:UIBarButtonItemStylePlain target:self action:@selector(eitAction:)];
        item.tintColor = [UIColor blackColor];
        self.navigationItem.rightBarButtonItem = item;
    }
    
    UIImageView *iconimg = [[UIImageView alloc]initWithFrame:CGRectMake(10, 7, 17, 17)];
    iconimg.image = [UIImage imageNamed:@"xqjob"];
    [_view_bg addSubview:iconimg];
    UILabel *joblable = [[UILabel alloc]initWithFrame:CGRectMake(50, 0, 200, 30)];
    joblable.text = _model.job;
    joblable.font = [UIFont systemFontOfSize:15];
    [_view_bg addSubview:joblable];
    
    
    UIImageView *gximg = [[UIImageView alloc]initWithFrame:CGRectMake(10, 47, 17, 17)];
    gximg.image = [UIImage imageNamed:@"xqgx"];
    [_view_bg addSubview:gximg];
    UILabel *gxlable = [[UILabel alloc]initWithFrame:CGRectMake(50, 40, 200, 30)];
    gxlable.text = _model.hometown;
    gxlable.font = [UIFont systemFontOfSize:15];
    [_view_bg addSubview:gxlable];
    
    
    UIImageView *xzimg = [[UIImageView alloc]initWithFrame:CGRectMake(10, 87, 17, 17)];
    xzimg.image = [UIImage imageNamed:@"xqxz"];
    [_view_bg addSubview:xzimg];
    UILabel *xzlable = [[UILabel alloc]initWithFrame:CGRectMake(50, 80, 200, 30)];
    xzlable.text = _model.xingzuo;
    xzlable.font = [UIFont systemFontOfSize:15];
    [_view_bg addSubview:xzlable];
    
    CGRect r = _view_bg.frame;
    r.size.height = xzlable.frame.size.height+xzlable.frame.origin.y;
    _view_bg.frame = r;

}
#pragma mark 编辑
-(void)eitAction:(UIBarButtonItem *)btn{
    UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"U"
                                                                 bundle:[NSBundle mainBundle]];
    RegisterSViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"RegisterSVC"];
    searchResultDetailController.iseit = @"编辑";
    searchResultDetailController.model = _model;
    [self.navigationController pushViewController:searchResultDetailController animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
